﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TuringCup;
namespace TuringCupAI
{

    public class GameAI
    {
        const String teamname = "SampleAI";
        int side = -1;
        public void init(int side)
        {
            this.side = side;
        }
        public String main(String str)
        {
            GameState gstate = GameState.Load(str);
            AI_Commands commands = new AI_Commands();
            String result = "";
            //
            List<int> mycell = new List<int>();
            for (int i = 0; i < gstate.cells.Count; i++)
            {
                if (gstate.cells[i].side == side)
                    mycell.Add(i);
            }
            for (int i = 0; i < gstate.cells.Count; i++)
            {
                if (gstate.cells[i].side != side && gstate.cells[i].hp > 39.0 && gstate.cells[i].ishero == false && mycell.Count > 0)
                    for (int j = 0; j < mycell.Count; j++)
                        commands.ntents.Add(new AI_Commands.NewTentacle(mycell[j], i));
            }
            for (int i = 0; i < gstate.tents.Count; i++)
            {
                GameState.Tentacle tent = gstate.tents[i];
                if (gstate.cells[tent.begin].side == side && tent.len1 + 1.0 > GameState.distance(gstate.cells[tent.begin], gstate.cells[tent.end]))
                {
                    commands.btents.Add(new AI_Commands.BreakTentacle(tent.begin, tent.end, tent.len1 / 3));
                }
            }
            result = commands.Serialize();
            return result;
        }
    }
}
